package com.hspedu.newData.dmsxl.链表.遍历;

import com.hspedu.newData.dmsxl.ds.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-07 
 * @Version: 1.0
 */

public class LC2130链表最大孪生和 {

    // 链表转集合
    public int pairSum(ListNode head) {

        List<Integer> list = new ArrayList<>();

        while (head != null){
            list.add(head.val);
            head = head.next;
        }

        int max = 0;

        int i = 0;
        int j = list.size() - 1;

        while(i<j){
            if ((list.get(i) + list.get(j)>max)){
                max = list.get(i) + list.get(j);
            }
            i++;
            j--;
        }
        return max;
    }

    // todo 快慢指针+反转链表
}
